# SPDX-FileCopyrightText: 2017-2023 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later

# --env-system-scripts allows to run without the install target.

# Use '--write-blend=/tmp/test.blend' to view output

set(TEST_SRC_DIR ${CMAKE_SOURCE_DIR}/../lib/tests)
set(TEST_OUT_DIR ${CMAKE_BINARY_DIR}/tests)

# ugh, any better way to do this on testing only?
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_OUT_DIR})

# if(NOT IS_DIRECTORY ${TEST_SRC_DIR})
#   message(FATAL_ERROR "CMake test directory not found!")
# endif()

# for testing with valgrind prefix: valgrind --track-origins=yes --error-limit=no
set(TEST_BLENDER_EXE $<TARGET_FILE:blender> --background -noaudio --factory-startup --debug-memory --debug-exit-on-error --env-system-scripts ${CMAKE_SOURCE_DIR}/scripts)


# ------------------------------------------------------------------------------

macro(view_layer_test test_name)
  # Adds ${CMAKE_CURRENT_LIST_DIR} to sys.path so that the tests can import
  # things from view_layer_common.py
  add_test(view_layer_${test_name} ${TEST_BLENDER_EXE}
    --python-expr "import sys; sys.path.append('${CMAKE_CURRENT_LIST_DIR}')"
    --python-exit-code 1
    --python ${CMAKE_CURRENT_LIST_DIR}/test_${test_name}.py --
    --testdir="${TEST_SRC_DIR}/layers"
  )
endmacro()

view_layer_test(active_collection)
view_layer_test(background_set)
view_layer_test(collection_new_sync)
view_layer_test(collection_rename_a)
view_layer_test(collection_rename_b)
# view_layer_test(evaluation_render_settings_a)
# view_layer_test(evaluation_render_settings_b)
# view_layer_test(evaluation_render_settings_c)
# view_layer_test(evaluation_render_settings_d)
# view_layer_test(evaluation_render_settings_e)
# view_layer_test(evaluation_render_settings_f)
# view_layer_test(evaluation_render_settings_g)
# view_layer_test(evaluation_render_settings_h)
# view_layer_test(evaluation_render_settings_i)
view_layer_test(evaluation_visibility_a)
view_layer_test(evaluation_visibility_b)
view_layer_test(evaluation_visibility_c)
view_layer_test(evaluation_visibility_d)
view_layer_test(evaluation_visibility_e)
view_layer_test(evaluation_visibility_f)
view_layer_test(evaluation_visibility_g)
view_layer_test(evaluation_visibility_h)
view_layer_test(evaluation_visibility_i)
view_layer_test(evaluation_visibility_j)
view_layer_test(evaluation_selectability_a)
view_layer_test(evaluation_selectability_b)
view_layer_test(evaluation_selectability_c)
view_layer_test(evaluation_selectability_d)
view_layer_test(evaluation_selectability_e)
view_layer_test(evaluation_selectability_f)
view_layer_test(group_a)
view_layer_test(group_b)
view_layer_test(group_c)
view_layer_test(group_d)
view_layer_test(group_e)
view_layer_test(object_add_cylinder)
view_layer_test(object_add_empty)
view_layer_test(object_add_torus)
view_layer_test(object_add_no_collection_cylinder)
view_layer_test(object_add_no_collection_empty)
view_layer_test(object_add_no_collection_torus)
view_layer_test(object_copy)
view_layer_test(object_delete_a)
view_layer_test(object_delete_b)
view_layer_test(object_link_a)
view_layer_test(object_link_b)
view_layer_test(object_link_c)
view_layer_test(operator_context)
view_layer_test(make_single_user)
view_layer_test(move_above_below_scene_collection_a)
view_layer_test(move_above_below_scene_collection_b)
view_layer_test(move_above_below_scene_collection_c)
view_layer_test(move_above_below_scene_collection_d)
view_layer_test(move_above_below_scene_collection_e)
view_layer_test(move_above_below_scene_collection_f)
view_layer_test(move_above_below_scene_collection_g)
view_layer_test(move_above_below_scene_collection_h)
view_layer_test(move_above_below_scene_collection_i)
view_layer_test(move_above_below_scene_collection_sync_a)
view_layer_test(move_above_below_scene_collection_sync_b)
view_layer_test(move_above_below_scene_collection_sync_c)
view_layer_test(move_above_below_scene_collection_sync_d)
view_layer_test(move_above_below_scene_collection_sync_e)
view_layer_test(move_above_below_scene_collection_sync_f)
view_layer_test(move_above_below_scene_collection_sync_g)
view_layer_test(move_above_below_scene_collection_sync_h)
view_layer_test(move_above_below_scene_collection_sync_i)
view_layer_test(move_into_scene_collection_a)
view_layer_test(move_into_scene_collection_b)
view_layer_test(move_into_scene_collection_c)
view_layer_test(move_into_scene_collection_d)
view_layer_test(move_into_scene_collection_e)
view_layer_test(move_into_scene_collection_f)
view_layer_test(move_into_scene_collection_g)
view_layer_test(move_into_scene_collection_h)
view_layer_test(move_into_scene_collection_i)
view_layer_test(move_into_scene_collection_j)
view_layer_test(move_into_scene_collection_k)
view_layer_test(move_into_scene_collection_l)
view_layer_test(move_into_scene_collection_sync_a)
view_layer_test(move_into_scene_collection_sync_b)
view_layer_test(move_into_scene_collection_sync_c)
view_layer_test(move_into_scene_collection_sync_d)
view_layer_test(move_into_scene_collection_sync_e)
view_layer_test(move_into_scene_collection_sync_f)
view_layer_test(move_into_scene_collection_sync_g)
view_layer_test(move_into_scene_collection_sync_h)
view_layer_test(move_into_scene_collection_sync_i)
view_layer_test(move_into_scene_collection_sync_j)
view_layer_test(move_into_scene_collection_sync_k)
view_layer_test(move_into_scene_collection_sync_l)
view_layer_test(move_above_below_layer_collection_a)
view_layer_test(move_above_below_layer_collection_b)
view_layer_test(move_above_below_layer_collection_c)
view_layer_test(move_above_below_layer_collection_d)
view_layer_test(move_above_below_layer_collection_e)
view_layer_test(move_above_below_layer_collection_f)
view_layer_test(move_above_below_layer_collection_g)
view_layer_test(move_above_below_layer_collection_h)
view_layer_test(move_above_below_layer_collection_i)
view_layer_test(move_above_below_layer_collection_j)
view_layer_test(move_above_below_layer_collection_k)
view_layer_test(move_above_below_layer_collection_l)
view_layer_test(move_into_layer_collection_a)
view_layer_test(move_into_layer_collection_b)
view_layer_test(move_into_layer_collection_c)
view_layer_test(move_into_layer_collection_d)
view_layer_test(move_into_layer_collection_e)
view_layer_test(move_into_layer_collection_f)
view_layer_test(move_into_layer_collection_g)
view_layer_test(move_into_layer_collection_h)
view_layer_test(move_into_layer_collection_i)
view_layer_test(move_into_layer_collection_j)
view_layer_test(layer_linking)
view_layer_test(layer_syncing)
view_layer_test(scene_collection_delete)
view_layer_test(scene_copy_a)
view_layer_test(scene_copy_b)
view_layer_test(scene_copy_c)
view_layer_test(scene_copy_d)
view_layer_test(scene_copy_e)
view_layer_test(scene_copy_f)
view_layer_test(scene_delete)
view_layer_test(scene_objects)
view_layer_test(scene_write_read)
view_layer_test(view_layer_rename)
